<template>
    <view class="list">
		<img :src="baseUrl+'api/uploads/'+options.image" alt="" srcset="" class='img_cla'/>
		
		<button
		    class="bg-primary text-lg text-white leading-[80rpx] h-[80rpx] rounded-full"
		    @click="saveImageQr"
		>
		    保存二维码
		</button>
		<br/>
		<br/>
		
		<view class="orderList_view">
			<uni-table ref="table"  border   emptyText="暂无更多数据" >
				<uni-tr>
					<!-- <uni-th align="center">订单编号</uni-th> -->
					<uni-th align="center">用户信息</uni-th>
					<uni-th align="center">实付金额</uni-th>
					<uni-th align="center">下单时间</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in options.orderList" :key="index">
					<!-- <uni-td align="center">{{ item.sn }}</uni-td> -->
					<uni-td align="center">{{ item.contact }}</uni-td>
					<uni-td align="center">{{ item.orderAmount }}</uni-td>
					<uni-td align="center">{{ item.createTime }}</uni-td>
				</uni-tr>
			</uni-table>
		</view>
		
		<view class="orderList_view">
			<uni-table ref="table"  border emptyText="暂无更多数据" >
				<uni-tr>
					<uni-th align="center">用户名称</uni-th>
					<uni-th align="center">绑定时间</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in options.userList" :key="index">
					<uni-td align="center">{{ item.userName }}</uni-td>
					<uni-td align="center">{{ item.createTime }}</uni-td>
				</uni-tr>
			</uni-table>
		</view>
    </view>
</template>

<script lang="ts" setup>
	import { ref, shallowRef,reactive } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { apiInvitationCode,apiReferrersOrderList, apiGetUserDetail } from '@/api/salescode'
import { log } from 'util';


const saveImageQr = async (): Promise<void> => {
    try {	
		let qrcodeUrl = baseUrl+'api/uploads/'+options.image;
        const res = await uni.getImageInfo({ src: qrcodeUrl})
        try {
            await uni.saveImageToPhotosAlbum({ filePath: res.path })
            uni.$u.toast('保存成功')
        } catch (e) {
            const modelRes = await uni.showModal({
                title: '图片保存失败',
                content: '请确认是否已开启授权'
            })
            if (modelRes.confirm) uni.openSetting()
        }
    } catch (err) {
        uni.$u.toast('请在小程序后台配置downloadFile')
    }
}
 
const baseUrl = `${import.meta.env.VITE_APP_BASE_URL || ''}/`
const options = reactive<{
    image: string,
	orderList:any[],
	userList:any[]
}>
({
    image: '',
	orderList:[],
	userList:[],
})
function queryList(){
    try {
        apiInvitationCode({}).then(res=>{
				options.image=res
		})
    } catch (error) {
        uni.$u.toast(error)
    }
}

function apiReferrersOrderListList(){
    try {
        apiReferrersOrderList({pageNo:1,pageSize:60}).then(res=>{
				options.orderList=res.lists
		})
    } catch (error) {
        uni.$u.toast(error)
    }
}
function apiGetUserDetailList(){
	try {
	    apiGetUserDetail({pageNo:1,pageSize:60}).then(res=>{
			options.userList=res.lists
		})
	} catch (error) {
	    uni.$u.toast(error)
	}
}
onShow(() => {
    queryList();
    apiReferrersOrderListList();
	apiGetUserDetailList();
})
</script>

<style lang="scss" scoped>
.list {
    text-align: center;
}

.empty {
    padding-top: 300rpx;
}
.img_cla{
	width: 300px;
	height: 300px;
	margin-top: 20px;
	margin-bottom: 20px;
}
</style>
